﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace AIniciacao.Lib.GameUtils
{
    public class DialogUtils
    {
        public static List<String> BuildMessageLines(SpriteFont Font, String Message, int bestFeetPositionXEnd)
        {
            int charCount = 0;
            String line = Message;
            List<String> lines = new List<string>();
            while (line.Length > 0)
            {
                Vector2 measure = Font.MeasureString(line);
                Boolean isLastCharBlank=false;
                while (measure.X > bestFeetPositionXEnd || isLastCharBlank)
                {
                    line = line.Substring(0, line.Length - 1);
                    measure = Font.MeasureString(line);
                    isLastCharBlank = !(line[line.Length - 1] == ' ');

                }
                charCount += line.Length;
                lines.Add(line);
                if (Message.Length > charCount)
                {
                    line =Message.Substring(charCount, (Message.Length - charCount));
                }
                else
                {
                    break;
                }
            }
            return lines;
        }
    }
}
